package com.cema.manage.project.manage.configuration.service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.cema.manage.project.enums.RiskEnum;
import com.cema.manage.project.manage.configuration.domain.Configuration;
import com.cema.manage.project.manage.configuration.mapper.ConfigurationMapper;
import com.cema.manage.project.system.config.domain.Config;
import com.cema.manage.redis.RedisService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 常规配置 服务层实现
 *
 * @author reasahi
 * @date 2024-07-22
 */
@Service
public class ConfigurationServiceImpl extends ServiceImpl<ConfigurationMapper, Configuration> implements IConfigurationService {

    private final String[] configurations = {"risk_double_open_app",
            "risk_double_open_backstage", "risk_simulator_app", "risk_simulator_backstage", "risk_developer_mode_app", "risk_developer_mode_backstage"
            , "risk_debug_mode_app", "risk_debug_mode_backstage", "risk_root_app", "risk_root_backstage", "risk_accessibility_app", "risk_accessibility_backstage"
            , "risk_id_proxy_app", "risk_id_proxy_backstage", "app_answer_incentive", "app_answer_sign_in", "app_answer_withdrawal", "app_full_screen", "ta_ku"
    };
    private final String[] configurationNo = {"gro_more"};

    @Resource
    private RedisService redisService;

    @Override
    public boolean setConfigurations(Integer vuChannel) {
        List<Configuration> configurationList = new ArrayList<>();
        for (String string : configurations) {
            Configuration configuration = new Configuration();
            configuration.setKey(string + vuChannel);
            configuration.setValue(RiskEnum.RISK_YES.getValue());
            redisService.set(configuration.getKey(), configuration.getValue());
            configurationList.add(configuration);
        }
        for (String string : configurationNo) {
            Configuration configuration = new Configuration();
            configuration.setKey(string + vuChannel);
            configuration.setValue(RiskEnum.RISK_NO.getValue());
            redisService.set(configuration.getKey(), configuration.getValue());
            configurationList.add(configuration);
        }
       return insertBatch(configurationList);
    }
}
